package game.web.controller;

import game.web.dao.dto.UserDTO;
import game.web.entity.UserEntityManager;
import game.web.struts.MyInfoForm;
import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class MyInfoSaveControllor extends ProjectXDbTrxController {
	
	protected MyInfoSaveControllor(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {

		debugBegin();

		UserContext uc = getUc();
		String ip = (String) uc.get(ConstantsProjectX.CURRENT_IP);
		String id = (String) uc.get(ConstantsProjectX.USER_ID);
		
		MyInfoForm form =(MyInfoForm)getForm();
		
		UserDTO myInfoUpdateDTO = new UserDTO();
		myInfoUpdateDTO.setUserid(id);
		myInfoUpdateDTO.setTruename(form.getMyinfo_truename());
		myInfoUpdateDTO.setFirstpass(form.getMyinfo_firstpass());
		myInfoUpdateDTO.setSecpass(form.getMyinfo_secpass());
		myInfoUpdateDTO.setContactno(form.getMyinfo_contactno());
		myInfoUpdateDTO.setUpdatetime(getCurrentTimeString());
		myInfoUpdateDTO.setUpdateip(ip);
		
		UserEntityManager.update(myInfoUpdateDTO);
		
		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new MyInfoSaveControllor(uc, form));
	}
}
